#!/bin/dash
#Program:
#      Search for information of trains from Harbin
#History:
#  2009/08/08    CodeFate    

echo "This program' fuction is searching for information of trains from Harbin!"
read -p "Where would you go:" dest
read -p "Input the time(YYYY-M-D)exa>2009-8-9:" time
wget -nv -O down1 "www.huoche.com.cn/city/haerbin"
grep $dest down1 | grep $time | grep "转让"  > res1
#nei include the information
nei="` cat res1 | cut -d '>' -f 3 `"
#zhi is a part of new URL
zhi="` cat res1 | cut -d '"' -f 4 `"
num=`cat res1 | wc -l`
echo $nei
echo "联系电话分别是："
for (( i=1; i<=$num; i=i+1 ))
do
declare -i fate=$(($i*2+1))
add="` echo $zhi | cut -d '/' -f $fate `"
www="http://wwww.huoche.com.cn/piao/"$add""
#www is the URL to the detail information 
wget -nv -O down2 "$www"
#Get the phone number
grep "联系电话" down2 > res2
call="` cat res2 | cut -d "'" -f 2 `"
echo $call
done
rm res1 res2 down1 down2
exit 0
